package com.touch.workshop.ui.expgrowth;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

import com.touch.workshop.Database;
public class Chart extends JInternalFrame implements KeyListener, InternalFrameListener
{
	private static final long serialVersionUID = 5086847823927406206L;
	private JTextField expval[];
	private JPanel b = new JPanel();
	private JScrollPane p = new JScrollPane(b);	
	public Chart()
	{				
		super("EXP Table", true, true, true, true);
		this.add(p);		
		this.addInternalFrameListener(this);
		this.setSize(640, 480);		
		this.expval = new JTextField[Database.MAXLEVEL + Database.MINLEVEL];
		this.setDefaultCloseOperation(JInternalFrame.HIDE_ON_CLOSE);
		b.setLayout(new GridLayout(Database.MAXLEVEL / 10, 10));				
	}	
	public void update()
	{
		for(int i = Database.MINLEVEL; i < Database.MAXLEVEL; i++)		
			Database.EXPCHART.set(i - 1, new Integer(expval[i].getText()));
		CurveControls.update();	
	}	
	public void keyPressed(KeyEvent e) 
	{
		if(e.getKeyCode() == KeyEvent.VK_ENTER)
		{
			this.update();
			this.setVisible(false);
		}
		
	}
	public void keyReleased(KeyEvent arg0) 			{}
	public void keyTyped(KeyEvent arg0) 			{}
	public void internalFrameActivated(InternalFrameEvent e) 	{}
	public void internalFrameClosed(InternalFrameEvent e)		{}
	public void internalFrameClosing(InternalFrameEvent e) 
	{
		this.update();
	}
	public void internalFrameDeactivated(InternalFrameEvent e)	{}
	public void internalFrameDeiconified(InternalFrameEvent e) 	{}
	public void internalFrameIconified(InternalFrameEvent e) 	{}
	public void internalFrameOpened(InternalFrameEvent e) 
	{	
		for(int i = Database.MINLEVEL; i < Database.MAXLEVEL; i++)
		{
			expval[i] = new JTextField();
			expval[i].setText(Database.EXPCHART.elementAt(i - 1).toString());
			b.add(expval[i]);
			expval[i].addKeyListener(this);
		}	
	}
}
